package org.wedding.center.pay.wxpay.config;

import lombok.Data;
import lombok.Getter;
import lombok.Setter;
import lombok.ToString;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.ClassPathResource;
import org.springframework.core.io.ResourceLoader;
import org.springframework.stereotype.Component;

import java.io.File;


/**
 * <p>IJPay 让支付触手可及，封装了微信支付、支付宝支付、银联支付常用的支付方式以及各种常用的接口。</p>
 *
 * <p>不依赖任何第三方 mvc 框架，仅仅作为工具使用简单快速完成支付模块的开发，可轻松嵌入到任何系统里。 </p>
 *
 * <p>IJPay 交流群: 723992875、864988890</p>
 *
 * <p>Node.js 版: <a href="https://gitee.com/javen205/TNWX">https://gitee.com/javen205/TNWX</a></p>
 *
 * <p>微信配置 Bean</p>
 *
 * @author Javen
 */
@Setter
@ToString
@Component
@Configuration
@ConfigurationProperties(prefix = "wx.v3")
public class WxPayV3Bean {
    @Autowired
    private ResourceLoader resourceLoader;

    @Getter
    private String appId;
    private String temPath;
    private String keyPath;
//    private String publicKeyPath;
    private String certPath;
    private String certP12Path;
    private String platformCertPath;
    @Getter
    private String pubKey;
    @Getter
    private String mchId;
    @Getter
    private String apiKey;
    @Getter
    private String apiKey3;
    @Getter
    private String domain;


    public String getKeyPath() {
        try {
            return JarResourceExtractor.getPemFile(keyPath, temPath).getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public String getPubKey() {
        try {
            return JarResourceExtractor.getPemFile(pubKey, temPath).getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public String getCertPath() {
        try {
            return JarResourceExtractor.getPemFile(certPath, temPath).getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public String getCertP12Path() {
        try {
            return JarResourceExtractor.getPemFile(certP12Path, temPath).getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }

    public String getPlatformCertPath() {
        try {
            return JarResourceExtractor.getPemFile(platformCertPath, temPath).getAbsolutePath();
        } catch (Exception e) {
            e.printStackTrace();
            throw new RuntimeException(e);
        }
    }
//    public String getKeyPath() {
//        try {
//            return JarResourceExtractor.extractResource(keyPath, temPath).getAbsolutePath();
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//    }
//
//    public String getPublicKeyPath() {
//        try {
//            return JarResourceExtractor.extractResource(publicKeyPath, temPath).getAbsolutePath();
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//    }
//
//    public String getCertPath() {
//        try {
//            return JarResourceExtractor.extractResource(certPath, temPath).getAbsolutePath();
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//    }
//
//    public String getCertP12Path() {
//        try {
//            return JarResourceExtractor.extractResource(certP12Path, temPath).getAbsolutePath();
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//    }
//
//    public String getPlatformCertPath() {
//        try {
//            return JarResourceExtractor.extractResource(platformCertPath, temPath).getAbsolutePath();
//        } catch (Exception e) {
//            e.printStackTrace();
//            throw new RuntimeException(e);
//        }
//    }


}
